layui.use(['form','layer','jquery','laypage','laydate'],function() {
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        $ = layui.jquery,
        laydate = layui.laydate;
    var Id = $.getQueryString("bh");
    $.fn.formEdit = function (data) {
        return this.each(function () {
            var input, name;
            if (data == null) {
                this.reset();
                return;
            }
            for (var i = 0; i < this.length; i++) {
                input = this.elements[i];
                //checkbox的name可能是name[]数组形式
                name = (input.type == "checkbox") ? input.name.replace(/(.+)\[\]$/, "$1") : input.name;
                if (data[name] == undefined) continue;
                switch (input.type) {
                    case "checkbox":
                        if (data[name] == "") {
                            input.checked = false;
                        } else {
                            //数组查找元素
                            if (data[name].indexOf(input.value) > -1) {
                                input.checked = true;
                            } else {
                                input.checked = false;
                            }
                        }
                        break;
                    case "radio":
                        if (data[name] == "") {
                            input.checked = false;
                            form.render();
                        } else if (input.value == data[name]) {
                            input.checked = true;
                            form.render();
                        }
                        break;
                    case "button":
                        break;
                    default:
                        input.value = data[name];
                }
            }
        });
    };
    if (Id) {
        $.ajax({
            contentType:'application/x-www-form-urlencoded; charset=UTF-8',
            url:detail,
            data: {bh: Id},
            type: "post",
            dataType: "json",
            async: false,
            success: function (data) {
                var td=data.data[0];
                if(td.sfyc==1){
                    $(".ccsj").removeClass("layui-hide")
                }else{
                    $(".ccsj").addClass("layui-hide")
                }
                $(".layui-upload-list").append("<img src='"+td.file+"' >")
                console.log(td)
                $("#form").formEdit(td)

            }
        });
    }

})